home *** CD-ROM | disk | FTP | other *** search
- /*
- Copyright © 1991-1995 by TopSoft Inc. All rights reserved.
-
- You may distribute this file under the terms of the TopSoft
- Artistic License, accompanying this package.
-
- This file was developed by George (ty) Tempel in connection with TopSoft, Inc..
- See the Modification History for more details.
-
- Product
- About Box
-
- FILE
- ABTopic.c
-
- NAME
- ABTopic.c, part of the ABox project source code,
- responsible for handling the AboutBox Topic class stuff.
-
- DESCRIPTION
- This file contains defines for the about box modules.
-
- DEVELOPED BY
- George (ty) Tempel netromancr@aol.com
- All code in this file, and its associated header file was
- Created by George (ty) Tempel in connection with the TopSoft, Inc.
- "FilterTop" application development, except where noted.
-
- CARETAKER - George (ty) Tempel <netromancr@aol.com>
- Please consult this person for any changes or suggestions to this file.
-
- MODIFICATION HISTORY
-
- dd mmm yy - xxx - patchxx: description of patch
- 9 June 94 - ty - Initial Version Created
- 20-july-94 - ty - initial version released
- 28-july-94 - ty - 1.0.6 -- removed cursor code to mix-in class
- ABUCursor; removed cursor flipping from Load
- 23-may-95 - ty - changes for compatibility with the CodeWarrior CW6
- release and the associated Universal Headers from Apple:
- most methods that returned references now have "Ref" at
- the end of their methods names to prevent possible collisions
- with datatypes and classes of the same name (older versions
- of the compiler didn't have a problem with this).
- */
-
- /*===========================================================================*/
-
- /*======= Segmentation directives ========*/
-
- #ifdef USE_MANUAL_SEGMENTATION
- #pragma segment ty
- #endif
-
- /*============ Header files ==============*/
-
- #include "ABTopic.h"
- #include "ABoxDefs.h"
- #include "ABSlide.h"
-
-
- #include "ABPict.h"
- #include "ABText.h"
- #include "ABStr.h"
- #include "ABSound.h"
-
- #include "ABUCursor.h"
-
- /*=============== Globals ================*/
-
- /*================ CODE ==================*/
-
-
- /*=============================== ABTopic::ABTopic ================================*/
- ABTopic::ABTopic(void)
- {
- this->InitializeTopic();
- } // end ABTopic
-
-
-
- /*=============================== ABTopic::ABTopic ================================*/
- ABTopic::ABTopic(const FSSpec& inTopicFSSpec)
- {
- this->InitializeTopic();
- (void)this->CheckAndCopyFSSpec(inTopicFSSpec);
- } // end ABTopic
-
-
-
- /*=============================== ABTopic::InitializeTopic ================================*/
- void
- ABTopic::InitializeTopic(void)
- {
- this->SlidesRef() = new ABLinkedList;
- this->FSSpecPointerRef() = NULL;
- this->NameRef() = (StringPtr)::NewPtrClear (kABTopicNameSize);
- this->FileRefNumRef() = kABBadTopicFileRefNum;
- this->TopicType() = ETopicType_Topic;
- } // end InitializeTopic
-
-
-
- /*=============================== ABTopic::~ABTopic ================================*/
- ABTopic::~ABTopic(void)
- {
- (void)this->CloseTopicFile();
-
- if (this->HasFSSpecPointer())
- {
- ::DisposPtr ((Ptr)this->FSSpecPointerRef());
- this->FSSpecPointerRef() = NULL;
- }
-
- if (this->HasNameRef())
- {
- ::DisposPtr ((Ptr)this->NameRef());
- this->NameRef() = NULL;
- }
-
- this->ResetSlideInfo();
-
- } // end ~ABTopic
-
-
-
- /*=============================== ABTopic::ResetSlideInfo ================================*/
- void
- ABTopic::ResetSlideInfo(void)
- {
- if (this->HasSlides())
- {
- delete this->SlidesRef();
- this->SlidesRef() = NULL;
- }
-
- } // end ResetSlideInfo
-
-
-
- /*=============================== ABTopic::ResetFileInfo ================================*/
- void
- ABTopic::ResetFileInfo(void)
- {
- this->ResetFSSpecPointer();
- this->ResetFileRefNum();
- } // end ResetFileInfo
-
-
-
-
- /*=============================== ABTopic::ResetFSSpecPointer ================================*/
- void
- ABTopic::ResetFSSpecPointer(void)
- {
- if (this->HasFSSpecPointer())
- {
- ::DisposPtr ((Ptr)this->FSSpecPointerRef());
- this->FSSpecPointerRef() = NULL;
- }
-
- } // end ResetFSSpecPointer
-
-
-
- /*=============================== ABTopic::ResetFileRefNum ================================*/
- void
- ABTopic::ResetFileRefNum(void)
- {
- this->FileRefNumRef() = kABBadTopicFileRefNum;
-
- } // end ResetFileRefNum
-
-
-
-
-
- /*=============================== ABTopic::UseTopicResFile ================================*/
- short
- ABTopic::UseTopicResFile(void) const
- {
- short oldResFile = ::CurResFile();
-
- if (this->HasFileRefNum())
- ::UseResFile(this->GetFileRefNum());
-
- return oldResFile;
- } // end UseTopicResFile
-
-
-
- /*=============================== ABTopic::ResizeAndDraw ================================*/
- OSErr
- ABTopic::ResizeAndDraw(Rect& inItemRect, WindowPtr inWindow)
- {
- OSErr anError = noErr;
-
- anError = this->Resize(&inItemRect);
- if (anError == noErr)
- anError = this->EraseFrame(inItemRect);
- if (anError == noErr)
- anError = this->Draw(inWindow);
-
- return anError;
- } // end ResizeAndDraw
-
-
- /*=============================== ABTopic::GetProperty ================================*/
- OSErr ABTopic::GetProperty(ABProperty prop,
- void *ptr,
- long *ptrSize)
- {
- OSErr error = noErr;
- long pSize;
-
- // begin here...
-
- if (!ptr)
- return kABPropertyNullStorage;
-
- switch (prop)
- {
- case kABTopicIndex:
- *((ABIndex *)ptr) = this->Ordinal();
- pSize = kABTopicIndexSize;
- break;
- case kABTopicNumberOfSlides:
- if (this->HasSlides())
- *((ABListCount *)ptr) = this->SlidesRef()->Count();
- else
- *((ABListCount *)ptr) = 0;
- pSize = kABTopicNumberOfSlidesSize;
- break;
- case kABTopicFSSpec:
- if (this->HasFSSpecPointer())
- *((FSSpecPtr)ptr) = *(this->FSSpecPointerRef());
- pSize = kABTopicFSSpecSize;
- break;
- case kABTopicName:
- if (this->HasNameRef())
- ::BlockMove (this->NameRef(), (Ptr)ptr, *(this->NameRef())+1);
- pSize = kABTopicNameSize;
- break;
- case kABTopicDepth:
- *((long *)ptr) = this->Depth();
- pSize = kABTopicDepthSize;
- break;
- case kABTopicType:
- *((ETopicType *)ptr) = this->TopicType();
- pSize = kABTopicTypeSize;
- break;
- default:
- error = kABTopicSuperProperties::GetProperty(prop, ptr, ptrSize);
- break;
- } // end switch block
-
- if (ptrSize && !error)
- *ptrSize = pSize;
- return error;
-
- } // end GetProperty
-
-
-
- /*=============================== ABTopic::SetProperty ================================*/
- OSErr ABTopic::SetProperty(ABProperty prop,
- void *ptr,
- long ptrSize)
- {
- OSErr error = noErr;
-
- // begin here...
-
- if (!ptr)
- return kABPropertyNullStorage;
-
- switch (prop)
- {
- case kABTopicNumberOfSlides:
- case kABTopicFSSpec:
- case kABTopicName:
- case kABTopicDepth:
- case kABTopicType:
- error = kABPropertyReadOnly;
- break;
- default:
- error = kABTopicSuperProperties::SetProperty(prop, ptr, ptrSize);
- break;
- } // end switch block
-
- return error;
-
- } // end SetProperty
-
-
-
-
-
- /*=============================== ABTopic::Draw ================================*/
- OSErr ABTopic::Draw(WindowPtr window)
- {
- OSErr error = noErr;
-
- ABSlide *slide = NULL;
- short curResFile = ::CurResFile();
-
- // begin here...
- //
- short oldResFile = this->UseTopicResFile();
-
- slide = this->CurrentSlide();
- if (slide)
- error = slide->Draw(window);
-
- ::UseResFile (oldResFile);
-
- return error;
-
- } // end Draw
-
-
-
- /*=============================== ABTopic::Update ================================*/
- OSErr ABTopic::Update(WindowPtr window)
- {
- OSErr error = noErr;
-
- ABSlide *slide = NULL;
-
- // begin here...
- //
- short oldResFile = this->UseTopicResFile();
-
- slide = this->CurrentSlide();
- if (slide)
- error = slide->Update(window);
-
- ::UseResFile (oldResFile);
-
- return error;
-
- } // end Update
-
-
-
-
- /*=============================== ABTopic::Event ================================*/
- Boolean ABTopic::Event(EventRecord *eventRec)
- {
- Boolean handled = false;
-
- ABSlide *slide = NULL;
-
- // begin here...
- //
- short oldResFile = this->UseTopicResFile();
-
- slide = this->CurrentSlide();
- if (slide)
- handled = slide->Event(eventRec);
-
- ::UseResFile(oldResFile);
-
- return handled;
-
- } // end Event
-
-
-
- /*=============================== ABTopic::Stop ================================*/
- OSErr ABTopic::Stop(void)
- {
- OSErr error = noErr;
- ABSlide *slide = NULL;
-
- // begin here...
- //
- short oldResFile = this->UseTopicResFile();
-
- slide = this->CurrentSlide();
- if (slide)
- error = slide->Stop();
-
- ::UseResFile (oldResFile);
-
- return error;
-
- } // end Stop
-
-
-
-
- /*=============================== ABTopic::NextSlide ================================*/
- OSErr ABTopic::NextSlide(void)
- {
- OSErr error = noErr;
- ABSlide *slide;
-
- error = this->Stop();
- if (this->HasSlides())
- {
- slide = (ABSlide *)(this->SlidesRef()->NextLink());
- } // end if (slides)
-
- return error;
- } // end NextSlide
-
-
-
-
- /*=============================== ABTopic::PreviousSlide ================================*/
- OSErr ABTopic::PreviousSlide(void)
- {
- OSErr error = noErr;
- ABSlide *slide;
-
- error = this->Stop();
- if (this->HasSlides())
- {
- slide = (ABSlide *)(this->SlidesRef()->PreviousLink());
- } // end if (slides)
-
- return error;
- } // end PreviousSlide
-
-
-
- /*=============================== ABTopic::CurrentSlide ================================*/
- ABSlide *ABTopic::CurrentSlide(void)
- {
- if (this->HasSlides())
- {
- return (ABSlide *)(this->SlidesRef()->GetCurrentLink());
- } else {
- return NULL;
- } // end if (slides)
-
- } // end CurrentSlide
-
-
-
- /*=============================== ABTopic::GotoSlide ================================*/
- OSErr ABTopic::GotoSlide(long number)
- {
- OSErr error = noErr;
- ABSlide *slide;
-
- error = this->Stop();
- if (this->HasSlides())
- {
- slide = (ABSlide *)(this->SlidesRef()->GotoLink(number));
- if (!slide)
- error = paramErr;
- } // end if (slides)
-
- return error;
- } // end GotoSlide
-
-
-
-
-
-
- /*=============================== ABTopic::Resize ===============================*/
- //
- // this function will rearrange and resize the picture and the
- // text fields that appear on a slide.
- //
- // This method will cause the current slide for the
- // topic to resize by invoking that item's resize method.
- //
- // is called by:
- //
- OSErr ABTopic::Resize (Rect const *field)
- {
- OSErr error = noErr;
- ABSlide *currentSlide = NULL;
-
- // begin here...
-
- if (field == NULL)
- return paramErr;
-
- Rect box = *field;
- error = this->SetProperty(kABObjectRect, &box, kABObjectRectSize);
- if (error != noErr)
- return error;
-
- if (this->HasSlides())
- currentSlide = (ABSlide *) this->SlidesRef()->GetCurrentLink();
-
- if (currentSlide)
- error = currentSlide->Resize(field);
-
- return error;
- } // end of Resize
-
-
-
-
- /*=============================== ABTopic::CheckAndCopyFSSpec ===============================*/
- //
- // This function will copy and/or create an FSSpecPtr
- // from the given parameter.
- //
- //
- OSErr ABTopic::CheckAndCopyFSSpec (const FSSpec& file)
- {
- OSErr error = noErr;
-
- // begin here...
-
- // the caller has specified a topic file to use,
- // so we'll replace whatever one we might have internally
- // with this one.
-
- if (this->DoesntHaveFSSpecPointer())
- {
- // oops! we need to create some storage first...
- this->FSSpecPointerRef() = (FSSpecPtr)::NewPtrClear(kABTopicFSSpecSize);
- error = ::MemError();
- if (error || this->DoesntHaveFSSpecPointer())
- {
- // yikes! storage failed! mayday!mayday! danger will robinson...
- if (!error)
- error = memFullErr;
- return error;
- } // end if block
- } // end if block
-
- // use the one passed as the argument, but save it
- // into the object's field
- ::BlockMove ((Ptr)&file, (Ptr)this->FSSpecPointerRef(), kABTopicFSSpecSize);
-
- return error;
- } // end CheckAndCopyFSSpec()
-
-
-
-
-
- /*=============================== ABTopic::OpenTopic ================================*/
- OSErr ABTopic::OpenTopic(void)
- {
- OSErr error = noErr;
-
- // begin here...
-
- ABUCursor::WatchCursor();
- if (this->HasFSSpecPointer())
- {
- this->FileRefNumRef() = ::FSpOpenResFile (this->FSSpecPointerRef(), fsRdPerm);
- error = ::ResError();
- } // end if block
-
- if (!error && this->HasFileRefNum())
- {
- (void)this->UseTopicResFile();
- error = this->GotoSlide(1);
- } // end if block
-
- ABUCursor::ArrowCursor();
- return error;
- } // end OpenTopic
-
-
-
-
- /*=============================== ABTopic::CloseTopicFile ================================*/
- OSErr ABTopic::CloseTopicFile(OSErr inError)
- {
- OSErr error = noErr;
-
- // begin here...
- error = this->CloseTopicFile();
-
- if (inError != noErr)
- this->ResetFileInfo();
-
- return error;
- } // end CloseTopicFile
-
-
-
- /*=============================== ABTopic::CloseTopicFile ================================*/
- OSErr ABTopic::CloseTopicFile(void)
- {
- OSErr error = noErr;
-
- // begin here...
- if (this->HasFSSpecPointer() && this->HasFileRefNum())
- {
- ::CloseResFile(this->FileRefNumRef());
- error = ::ResError();
- this->ResetFileRefNum();
- } // end if block
-
- return error;
- } // end CloseTopicFile
-
-
-
-
- /*=============================== ABTopic::CloseTopic ================================*/
- OSErr ABTopic::CloseTopic(void)
- {
- OSErr error = noErr;
-
- // begin here...
-
- ABUCursor::WatchCursor();
- error = this->Stop();
-
- if (error == noErr)
- error = this->CloseTopicFile();
-
- ABUCursor::ArrowCursor();
- return error;
- } // end CloseTopic
-
-
-
-
- /*=============================== ABTopic::Load ===============================*/
- //
- //
- OSErr ABTopic::Load (short inFileRefToUse)
- {
- OSErr error = noErr;
-
- this->FileRefNumRef() = inFileRefToUse;
-
- error = this->Load();
- return error;
-
- } // end of Load
-
-
-
-
- /*=============================== ABTopic::Load ===============================*/
- //
- //
- OSErr ABTopic::Load (void)
- {
- OSErr error = noErr;
-
- short count = 0;
- short id = 0;
- Handle rHandle = NULL;
- Ptr rPtr = NULL;
- ABSlide *slide = NULL;
- const short size = sizeof(short int);
- const short resourceIndex = 1;
- Boolean slideCount = false;
-
- // begin here...
-
- // if not given an FSSpecPtr, this topic will attempt to grab from the current
- // resource file.
- if (this->DoesntHaveFSSpecPointer() && this->DoesntHaveFileRefNum())
- {
- // we don't have a file to look at, or an open resource
- // file that we should look at, so return
- this->ResetFileInfo();
- error = resNotFound;
- } else {
- slideCount = this->DoCheckSlides();
- if (slideCount < 1)
- {
- // there wasn't anything of interest...
- //
- error = resNotFound;
- } // end if (error)
-
- } // end if block
-
- if (error == noErr)
- error = this->DoLoad();
-
- this->CloseTopicFile(error);
-
- return error;
-
- } // end of Load
-
-
-
- /*=============================== ABTopic::DoCheckSlides ===============================*/
- //
- // This function checks a file for the presense of a topic/slide definition
- // resource and will an error type (OSErr)
- //
- //
- // is called by:
- //
- short ABTopic::DoCheckSlides (void)
- {
- OSErr error = noErr;
- short tempRefNum, oldResFile;
- short count = 0;
-
- // begin here...
-
- oldResFile = ::CurResFile();
- if (this->HasFSSpecPointer())
- {
- // check the given file...
-
- tempRefNum = ::FSpOpenResFile (this->FSSpecPointerRef(), fsRdPerm);
- error = ::ResError();
- if (error)
- {
- ::UseResFile (oldResFile);
- return count;
- } // end if block
-
- } else if (this->HasFileRefNum()) {
- // check the preset, pre-opened resource file
- tempRefNum = this->FileRefNumRef();
- } else {
- // nothing to check, so leave...
- return count = 0;
- } // end if block
-
- ::UseResFile(tempRefNum);
- count = ::Count1Resources (kABTopicSlideResource);
- error = ::ResError();
-
- if (!error && count < 1)
- error = resNotFound;
-
- if (this->HasFSSpecPointer())
- {
- ::CloseResFile(tempRefNum);
- } // end if block
-
- ::UseResFile(oldResFile);
- return count;
-
- } // end of function DoCheckSlides
-
-
- /*=============================== ABTopic::DoLoad ===============================*/
- //
- //
- OSErr ABTopic::DoLoad (void)
- {
- OSErr error = noErr;
-
- short count = 0;
- short id = 0;
- Handle rHandle = NULL;
- Ptr rPtr = NULL;
- ABSlide *slide = NULL;
- short slideNumber;
- const short size = sizeof(short int);
- const short resourceIndex = 1;
- long index;
- short oldRefNum;
- Boolean slideCount = false;
-
- // begin here...
-
- // if not given an FSSpecPtr, this topic will attempt to grab from the current
- // resource file.
- if (this->DoesntHaveFSSpecPointer() && this->DoesntHaveFileRefNum())
- {
- // we don't have a file to look at, or an open resource
- // file that we should look at, so return
- this->ResetFileRefNum();
- return resNotFound;
- } // end if block
-
- // we did find a slide resource, so now get it and
- // process it.
- oldRefNum = ::CurResFile();
- if (this->HasFSSpecPointer())
- {
- // the caller specified a file to use, so save the
- // old one and open the new one.
- this->FileRefNumRef() = ::FSpOpenResFile (this->FSSpecPointerRef(), fsRdPerm);
- error = ::ResError();
- if (error)
- {
- this->ResetFileRefNum();
- ::UseResFile (oldRefNum);
- return error;
- } // end if else block
- } // end if block
-
- // set the resource file!
- (void)this->UseTopicResFile();
-
- // get the resource.
- rHandle = ::Get1IndResource (kABTopicSlideResource, resourceIndex);
- error = ::ResError();
-
- if (rHandle && !error && this->HasSlides())
- {
- // we got everything we needed without a problem, so
- // load the resource into a data structure.
-
- ::HLock (rHandle);
- rPtr = *rHandle;
-
- // we have the resource, so now load it into a data structure
- //
- // find out how large the list is:
- ::BlockMove (rPtr, (Ptr)&count, size);
- rPtr += size;
-
- for (index = 1; (index <= count) && rPtr; ++index)
- {
- // grab the next item from the resource
- ::BlockMove (rPtr, (Ptr)&(slideNumber), size);
- rPtr += size;
-
- // create a new slide...
- slide = new ABSlide;
- if (slide)
- {
- error = slide->SetProperty(kABSlideNumber, &slideNumber, kABSlideNumberSize);
- this->SlidesRef()->Append(slide);
- } // end if (slide)
-
- } // end for(index) loop
-
- ::HUnlock (rHandle);
-
- } // end if block
-
- // clean up time!
- //
- if (rHandle)
- ::ReleaseResource(rHandle);
-
- ::UseResFile (oldRefNum);
-
- return error;
-
- } // end of function DoLoad
-
-
-
-
-
-
- // end of file
-
-